package com.kaesar.leetcode.LeetCode_051_100;

public class LeetCode_062 {
    /**
     * 递归
     *
     * @param m
     * @param n
     * @return
     */
    public static int uniquePaths(int m, int n) {
        if (m == 1 || n == 1) {
            return 1;
        }
        return uniquePaths(m - 1, n) + uniquePaths(m, n - 1);
    }

    /**
     * 迭代
     *
     * @param m
     * @param n
     * @return
     */
    public static int uniquePaths1(int m, int n) {
        if (m == 1 || n == 1) {
            return 1;
        }
        int[] row = new int[n];
        for (int i = 0; i < n; i++) {
            row[i] = 1;
        }
        for (int i = 2; i <= m; i++) {
            for (int x = 1; x < row.length; x++) {
                row[x] = row[x - 1] + row[x];
            }
        }
        return row[n - 1];
    }

    public static void main(String[] args) {
        System.out.println(uniquePaths(51, 9));
        System.out.println(uniquePaths1(51, 9));
    }
}
